// Color Extensions
import 'dart:ui';

extension ExColor on Color {
  int get alpha => (a * 255).round();

  int get red => withValues(colorSpace: ColorSpace.extendedSRGB).r.round();

  int get green => withValues(colorSpace: ColorSpace.extendedSRGB).g.round();

  int get blue => withValues(colorSpace: ColorSpace.extendedSRGB).b.round();

  /// return hex String
  String toHex({bool leadingHashSign = true, bool includeAlpha = false}) =>
      '${leadingHashSign ? '#' : ''}'
      '${includeAlpha ? alpha.toRadixString(16).padLeft(2, '0') : ''}'
      '${red.toRadixString(16).padLeft(2, '0')}'
      '${green.toRadixString(16).padLeft(2, '0')}'
      '${blue.toRadixString(16).padLeft(2, '0')}';

  /// return true if given color is dark
  bool isDark() => getBrightness() < 128;

  /// return true if given color is light
  bool isLight() => !isDark();

  /// return Brightness of give Color
  double getBrightness() => (red * 299 + green * 587 + blue * 114) / 1000;

  /// 返回颜色亮度
  double getLuminance() => computeLuminance();
}
